package com.dzk.cp.c11x5.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

public class C11x5Utils {
	
	public static List<Integer> getRN(int n) {
		List<Integer> list = new ArrayList<Integer>();
		Random r = new Random();
		List<Integer> tmpList = new LinkedList<Integer>(Arrays.asList(new Integer[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11}));
		for (int i = 0; i < n; i++) {
			int j = r.nextInt(tmpList.size());
			list.add(tmpList.get(j));
			tmpList.remove(j);
		}
		Collections.sort(list);
		return list;
	}
	
	public static boolean contain(List<?> list1, List<?> list2) {
		if (list1.size() >= list2.size()) {
			return list1.containsAll(list2);
		}
		return list2.containsAll(list1);
	}
	
	public static boolean contain(Object[] arr1, Object[] arr2) {
		if (arr1.length >= arr2.length) {
			for (int i = 0; i < arr2.length; i++) {
				boolean b = false;
				for (int j = 0; j < arr1.length; j++) {
					if (arr2[i].equals(arr1[j])) {
						b = true;
						break;
					}
				}
				if (!b) {
					return false;
				}
			}
			return true;
		}
		return contain(arr2, arr1);
	}
	
	public static int getOddNum(List<Integer> list) {
		int n = 0;
		for (int a : list) {
			if (a % 2 != 0) {
				n++;
			}
		}
		return n;
	}
	
	public static int getEvenNum(List<Integer> list) {
		int n = 0;
		for (int a : list) {
			if (a % 2 == 0) {
				n++;
			}
		}
		return n;
	}
	
	public static int getBigNum(List<Integer> list) {
		int n = 0;
		for (int a : list) {
			if (a > 5) {
				n++;
			}
		}
		return n;
	}
	
	public static int getSmallNum(List<Integer> list) {
		int n = 0;
		for (int a : list) {
			if (a < 6) {
				n++;
			}
		}
		return n;
	}
	
	public static int getY0Num(List<Integer> list) {
		int n = 0;
		for (int a : list) {
			if (a % 3 == 0) {
				n++;
			}
		}
		return n;
	}
	
	public static int getY1Num(List<Integer> list) {
		int n = 0;
		for (int a : list) {
			if (a % 3 == 1) {
				n++;
			}
		}
		return n;
	}
	
	public static int getY2Num(List<Integer> list) {
		int n = 0;
		for (int a : list) {
			if (a % 3 == 2) {
				n++;
			}
		}
		return n;
	}
	
	public static int getSum(List<Integer> list) {
		int n = 0;
		for (int a : list) {
			n += a;
		}
		return n;
	}
	
	public static int getKd(List<Integer> list) {
		return list.get(list.size() - 1) - list.get(0);
	}
	
	public static int getLX(List<Integer> list) {
		int n = 0;
		for (int i = 0; i < list.size() - 1; i++) {
			if (list.get(i + 1) - list.get(i) == 1) {
				n++;
			}
		}
		return n;
	}
	
	public static int getCM(List<Integer> list1, List<Integer> list2) {
		int n = 0;
		if (list1 != null && list2 != null) {
			for (int i = 0; i < list1.size(); i++) {
				for (int j = 0; j < list2.size(); j++) {
					if (list1.get(i).equals(list2.get(j))) {
						n++;
						break;
					}
				}
			}
		}
		return n;
	}
	
	public static int getLX2(List<Integer> list) {
		if (is0L0L(list)) {
			return 0;
		} else if (is2L0L(list)) {
			return 1;
		} else if (is2L2L(list)) {
			return 2;
		} else if (is3L0L(list)) {
			return 3;
		} else if (is3L2L(list)) {
			return 4;
		} else if (is4L0L(list)) {
			return 5;
		} else {
			return 6;
		}
	}
	
	public static boolean is0L0L(List<Integer> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			if (list.get(i + 1) - list.get(i) == 1) {
				return false;
			}
		}
		return true;
	}
	
	public static boolean is2L0L(List<Integer> list) {
		int n = 0;
		for (int i = 0; i < list.size() - 1; i++) {
			if (list.get(i + 1) - list.get(i) == 1) {
				n++;
			}
		}
		return n == 1;
	}
	
	public static boolean is2L2L(List<Integer> list) {
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < list.size() - 1; i++) {
			builder.append(list.get(i + 1) - list.get(i));
		}
		return builder.toString().matches("^(1[2-9][2-9]1)|(1[2-9]1[2-9])|([2-9]1[2-9]1)$");
	}
	
	public static boolean is3L0L(List<Integer> list) {
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < list.size() - 1; i++) {
			builder.append(list.get(i + 1) - list.get(i));
		}
		return builder.toString().matches("^(11[2-9][2-9])|([2-9]11[2-9])|([2-9][2-9]11)$");
	}
	
	public static boolean is3L2L(List<Integer> list) {
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < list.size() - 1; i++) {
			builder.append(list.get(i + 1) - list.get(i));
		}
		return builder.toString().matches("^(11[2-9]1)|(1[2-9]11)$");
	}
	
	public static boolean is4L0L(List<Integer> list) {
		StringBuilder builder = new StringBuilder();
		for (int i = 0; i < list.size() - 1; i++) {
			builder.append(list.get(i + 1) - list.get(i));
		}
		return builder.indexOf("111") != -1 && !"1111".equals(builder.toString());
	}
	
	public static boolean is5L0L(List<Integer> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			if (list.get(i + 1) - list.get(i) != 1) {
				return false;
			}
		}
		return true;
	}
	
	public static boolean compare(int[] arr1, int[] arr2, int m) {
		for (int i = 0; i < m; i++) {
			if (arr1[i] != arr2[i]) {
				return false;
			}
		}
		return true;
	}

}
